<?php
// 简单测试AJAX请求的JSON响应

echo "=== 测试AJAX请求的JSON响应 ===\n\n";

// 测试URL列表（使用相对URL）
$testUrls = [
    'http://localhost:63342/Blog/admin.php?c=User&a=changeStatus&id=1&status=disable',
    'http://localhost:63342/Blog/admin.php?c=User&a=deleteUser&id=1'
];

foreach ($testUrls as $url) {
    testAjaxRequest($url);
}

echo "\n=== 测试完成 ===\n";

// 使用cURL测试AJAX请求的函数
function testAjaxRequest($url) {
    echo "\n测试URL: $url\n";
    
    // 创建cURL资源
    $ch = curl_init();
    
    // 设置URL和其他cURL选项
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, [
        'X-Requested-With: XMLHttpRequest'
    ]);
    
    // 执行cURL请求
    $response = curl_exec($ch);
    
    // 获取响应状态码
    $statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    
    // 关闭cURL资源
    curl_close($ch);
    
    echo "HTTP状态码: $statusCode\n";
    echo "响应长度: " . strlen($response) . " 字节\n";
    echo "响应内容(raw): " . $response . "\n";
    echo "响应内容(hex): " . bin2hex($response) . "\n";
    
    // 尝试解析JSON
    echo "尝试解析JSON: ";
    $data = json_decode($response);
    if (json_last_error() === JSON_ERROR_NONE) {
        echo "成功！\n";
        echo "解析结果: " . print_r($data, true) . "\n";
    } else {
        echo "失败！错误: " . json_last_error_msg() . "\n";
    }
}
?>